package com.demo.user;

import java.util.Map;

import org.nature.framework.bean.ValidatorFail;
import org.nature.framework.core.NatureMap;
import org.nature.framework.util.ValidatorUtil;
import org.nature.framework.validator.NatureValidator;

/**
 * 简单强大的后台验证
 * 使用@Validator定义到需要验证的方法上
 */
public class UserValidator implements NatureValidator{

	public ValidatorFail validate(NatureMap params, Map<String, String> errorMap) {
		String icon = "<i class='glyphicon glyphicon-info-sign'></i>";
		
		//使用自带验证工具
		ValidatorUtil.validate(params, errorMap, "user.name", ValidatorUtil.notBankRegx, "error_name", icon+"姓名不能为空");		
		
		//自定义
		int age = params.getInt("user.age");
		if (age<=0||age>=150) {
			errorMap.put("error_age", icon+"年龄范围错误");
		}
		
		return ValidatorFail.backTo("list");
	}

}
